#!/usr/bin/env bash

# set -e: exit asap if a command exits with a non-zero status
# set -x: print each command right before it is executed
set -xe

# ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew update
brew install wget || true

# https://github.com/caskroom/homebrew-cask/blob/master/USAGE.md#other-ways-to-specify-a-cask
# brew cask install ./osx/dockertoolbox-rc.rb --force
brew install docker docker-compose docker-machine docker-machine-driver-xhyve boot2docker
sudo chown root:wheel /usr/local/bin/docker-machine-driver-xhyve || true
sudo chmod u+s /usr/local/bin/docker-machine-driver-xhyve || true

# We don't want to use docker-machine
# docker-machine stop default || true

# Currently erroring:
#  https://travis-ci.org/elgalu/docker-selenium/jobs/143358317
#   com.docker.docker Incompatible CPU detected
#   Docker requires a processor with virtualization capabilities
# /Applications/Docker.app/Contents/MacOS/Docker &
# sleep 20
brew services start docker-machine
docker-machine create default --driver xhyve --xhyve-experimental-nfs-share || true
docker-machine start
#=> ERROR! vmx_init: processor not supported by Hypervisor.framework
# Apparently due to Travis using old Mac machines
# we will have to wait a couple of years

# Below will fail with
#  Error with pre-create check:
#    This computer doesn't have VT-X/AMD-v enabled.
#    Enabling it in the BIOS is mandatory
# for the time being, see
#  https://github.com/travis-ci/travis-ci/issues/5738#issuecomment-227167082
# docker-machine --restart || true
# docker-machine create --driver virtualbox default || true
# docker-machine --version
# docker-machine ls
# eval "$(docker-machine env default)"
docker --version
docker-compose --version
docker-machine version
# docker-machine env default
#=> Host does not exist: "default"
# docker-machine create --driver virtualbox default
#=> Error with pre-create check:
#=> "VBoxManage not found. Make sure VirtualBox is installed
#=> and VBoxManage is in the path"
eval "$(docker-machine env default)" || true
docker run --rm -t ubuntu uname -a
docker build -t selenium .
